// 用户相关的请求模块api接口
import request from '../utils/request'
// import store from "../store/index"
// 登录接口
export const login = data => {
    return request({
        method: 'POST',
        url: '/v1_0/authorizations',
        // post参数  ： data对象
        data
    })
}

// 获取验证码接口
export const code = mobile => {
    return request({
        method: 'GET',
        url: `/v1_0/sms/codes/${mobile}`,

    })
}

// 获取用户自己信息 token
export const getuserinfo = () => {
    return request({
        method: 'GET',
        url: "/v1_0/user",
        // headers:{
        //     Authorization:`Bearer ${store.state.usertoken.token}`
        // }
    })
}
// 获取用户频道
export const channels = () => {
    return request({
        method: 'GET',
        url: '/v1_0/user/channels'
    })
}

// 获取文章列表
export const atrs = (channel_id, timestamp) => {
    return request({
        method: 'GET',
        url: '/v1_0/articles',
        params: {
            channel_id,
            timestamp
        }
    })
}
//获取所有频道列表
export const allchannels = () => {
    return request({
        method: 'GET',
        url: '/v1_0/channels'
    })
}

// 添加频道，到我的频道
export const setmychannel = (channel) => {
    return request({
        method: 'PATCH',
        url: '/v1_0/user/channels',
        data: {
            channels: [channel]
        }
    })
}

// 删除我的频道
export const delmychannel = (target) => {
    return request({
        method: 'DELETE',
        url: `/v1_0/user/channels/${target}`,
    })
}

//获取联想建议
export const getsuggestions = (q) => {
    return request({
        method: 'GET',
        url: "/v1_0/suggestion",
        params: {
            q
        }
    })
}

//搜索结果
export const results = (q, page, per_page) => {
    return request({
        method: 'GET',
        url: "/v1_0/search",
        params: {
            q,
            page,
            per_page
        }
    })
}
//获取文章详细
export const atrcle = (id) => {
    return request({
        method: 'GET',
        url: `/v1_0/articles/${id}`,

    })
}

// 关注
export const followUserAPI = (target) => {
    return request({
        method: 'POST',
        url: '/v1_0/user/followings',
        // post参数  ： data对象
        data: {
            target
        }


    })
}

// 取消关注
export const onfollowUserAPI = (target) => {
    return request({
        method: 'DELETE',
        url: `/v1_0/user/followings/${target}`,


    })
}

// 收藏
export const collectAPI = (target) => {
    return request({
        method: 'POST',
        url: "/v1_0/article/collections",
        data: {
            target
        }

    })
}

// 取消收藏
export const oncollectAPI = (target) => {
    return request({
        method: 'DELETE',
        url: `/v1_0/article/collections/${target}`,

    })
}
// 点赞
export const likeAPI = (target) => {
    return request({
        method: 'POST',
        url: "/v1_0/article/likings",
        data: {
            target
        }

    })
}

// 取消点赞
export const onlikeAPI = (target) => {
    return request({
        method: 'DELETE',
        url: `/v1_0/article/likings/${target}`,

    })
}

// 获取评论
export const getcomments = (params) => {
    return request({
        method: 'GET',
        url: "/v1_0/comments",
        params
    })
}

// 对评论或评论回复点赞
export const setlikecount = (target) => {

    return request({
        method: 'post',
        url: "/v1_0/comment/likings",
        data: {
            target
        }
    })
}

//取消对评论或评论回复点赞
export const onlikecount = (target) => {

    return request({
        method: 'DELETE',
        url: `/v1_0/comment/likings/${target}`,

    })
}

//对文章或者评论进行评论
export const postcomment = (data) => {

    return request({
        method: 'POST',
        url: "/v1_0/comments",
        data
    })
}

// 编辑用户头像
export const setuserimge = (data) => {
    return request({
        method: 'PATCH',
        url: "/v1_0/user/photo",
        data
    })
}